﻿using System;
using System.Configuration;

namespace Components.Configuration
{
  internal class ConfigurationManager : ConfigurationSection
  {
    #region Singleton implementation
    ConfigurationManager()
    {
    }

    /// <summary>
    /// Returns a ConfigurationManager instance
    /// </summary>
    public static ConfigurationManager Instance
    {
        get
        {
            return Nested.instance;
        }
    }

    class Nested
    {
      // Explicit static constructor to tell C# compiler
      // not to mark type as beforefieldinit
      static Nested()
      {
      }

      internal static readonly ConfigurationManager instance = (ConfigurationManager)System.Configuration.ConfigurationManager.GetSection(ConfigurationManager.SECTION_NAME) ?? new ConfigurationManager();
    }
    #endregion

    private const String SECTION_NAME = "components";

    [ConfigurationProperty("fieldReferences")]
    public FieldReferenceCollection FieldReferences
    {
      get { return (FieldReferenceCollection)this["fieldReferences"] ?? new FieldReferenceCollection(); }
    }

    [ConfigurationProperty("controlBuilderReferences")]
    public ControlBuilderReferenceCollection ControlBuilderReferences
    {
      get { return (ControlBuilderReferenceCollection)this["controlBuilderReferences"] ?? new ControlBuilderReferenceCollection(); }
    }
  }
}